home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: expression must have class type
- Date: Thu, 25 Jan 1996 12:55:01 GMT
- Organization: Netcom
- Message-ID: <31077d2b.55409600@nntp.ix.netcom.com>
- References: <4e74k2$jku@NNTP.MsState.Edu>
- NNTP-Posting-Host: ix-dc7-21.ix.netcom.com
- X-NETCOM-Date: Thu Jan 25 4:54:53 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- topher@ERC.MsState.Edu (John Christopher Lakey) wrote:
-
- > I get this error when I use a constructor with no args,
- > but not when I use one with an arguement.
- >
- >
- > Here's a code example:
- >
- > class NexRadMessage {
- > public:
- >
- > NexRadMessage();
- > //NexRadMessage(char *filename);
- > ~NexRadMessage();
- >
- > ...
- >
- > };
- >
- >
- > NexRadMessage::NexRadMessage()
- > {
- > _messageCode = -1;
- > }
- >
- > NexRadMessage::NexRadMessage(char *filename)
- > {
- > if (filename)
- > loadMessage(filename);
- > else _messageCode = -1;
- > }
- >
- >
- > main(int argc,char **argv)
- > {
- >
- > //NexRadMessage message("argv[1]"); // tested and works (so far).
- > NexRadMessage message();
- >
- > message.loadMessage(argv[1]);
- >
- > }
- >
- > "nexrad.C", line 106: error(3240): expression must have class type
- > message.loadMessage(argv[1]);
- > ^
- > This work fine if I use the first declaration, but not the second.
- > Any clue what I've done wrong? I'm using IRIX 5.3 (NCC) C++
-
- The problem is that the declaration
-
- NexRadMessage message();
-
- isn't doing what you want. It is not defining message as an instance
- of NexRadMessage -- it's declarring it as a function returning
- NexRadMessage. Change this to
-
- NexRadMessage message;
-
-
- Michael M Rubenstein
-